<style>
    .layui-form-item .layui-inline {
        margin-top: 10px;
    }
</style>
<div class="layui-fluid" id="Ship-create">
    <div class="layui-card">
        <div class="layui-form" lay-filter="LAY-list-form">
            <div id="view"></div>
        </div>
    </div>
</div>
<script id="page1" type="text/html">
    <input type="hidden" name="id" value="{{layui.router().search.id||''}}">
    <div class="layui-card-header">配送计划资料</div>
    <div class="layui-card-body">
         {{# if(layui.router().search.type==2){ }}
        <div class="layui-btn-container">
            <button class="layui-btn" id="auditCancel">驳回</button>
            <button class="layui-btn" id="auditSuccess">通过</button>
         </div>
         {{# } }}
        <div class="layui-form-item">
            <div class="layui-inline">
                <label class="layui-form-label">配送计划号</label>
                <div class="layui-input-inline">
                    <span class="layui-input layui-input-none">{{d.plan.code||''}}</span>
                </div>
            </div>
            <div class="layui-inline">
                 <label class="layui-form-label">国家</label>
                <div class="layui-input-inline">
                    <span class="layui-input layui-input-none">{{d.plan.country_str_rec||''}}</span>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">*发运公司</label>
                <div class="layui-input-inline">
                    <span class="layui-input layui-input-none">{{d.plan.company_str_out||''}}</span>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">*发货仓库</label>
                <div class="layui-input-inline">
                    <span class="layui-input layui-input-none">{{d.plan.warehouse_str_out||''}}</span>
                </div>
            </div>
             <div class="layui-inline">
                <label class="layui-form-label layui-label-jy">*收货公司</label>
                <div class="layui-input-inline">
                    <span class="layui-input layui-input-none">{{d.plan.recieve_str_company||''}}</span>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">*收货店铺</label>
                <div class="layui-input-inline">
                    <span class="layui-input layui-input-none">{{d.plan.shop_str_rec||''}}</span>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">*收货仓库</label>
                <div class="layui-input-inline">
                    <input id="warehouse_id_rec" lay-verify="required"  name="warehouse_id_rec" value="{{d.plan.warehouse_id_rec||''}}"
                           type="hidden">
                    <span id="warehouse_str_rec"
                          class="layui-input layui-input-none">{{d.plan.warehouse_str_rec||''}}</span>
                </div>
            </div>


            <div class="layui-inline">
                <label class="layui-form-label layui-label-jy">*配送类型</label>
                <div class="layui-input-inline">
                     <span id="warehouse_str_rec"
                          class="layui-input layui-input-none">{{d.plan.type_status||''}}</span>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label  layui-label-jy">*需求配送时间</label>
                <div class="layui-input-inline">
                     <span id="warehouse_str_rec"
                          class="layui-input layui-input-none">{{d.plan.distribution_time||''}}</span>
                </div>
            </div>
            
            {{# if(layui.router().search.type>0){}}
            <div class="layui-inline">
                <label class="layui-form-label">创建人</label>
                <div class="layui-input-inline">
                    <span class="layui-input layui-input-none">{{d.plan.operator||''}}</span>
                </div>
            </div>
            <div class="layui-inline">
                <label class="layui-form-label">创建时间</label>
                <div class="layui-input-inline">
                    <span class="layui-input layui-input-none">{{d.plan.ctime||''}}</span>
                </div>
            </div>
            {{# } }}
        </div>
    </div>

    <div class="layui-card-header">商品信息</div>
    <div class="layui-card-body">
        <div class="layui-tab">
            <div class="layui-tab-content">
                <div class="tab1 layui-tab-item layui-show">
                    <div class="layui-item">
                        {{# if(!(layui.router().search.type==2)) { }}
                        <button class="export1 layui-btn">导出</button>
                        {{#} }}
                    </div>
                    <table id="LAY-list" lay-filter="LAY-list"></table>
                </div>
            </div>
        </div>
    </div>

    <div class="layui-card-body layui-jy-center">
        <a lay-href="Distribution/index" class="layui-btn">返回</a>
    </div>

</script>
<!-- 行内工具 -->
<script>
    layui.use(['admin', 'form', 'toolJ', 'laytpl', 'laydate', 'upload', 'table','multiSelect'], function () {
        var $ = layui.$
            , form = layui.form
            , laytpl = layui.laytpl
            , setter = layui.setter
            , laydate = layui.laydate
            , table = layui.table
            , toolJ = layui.toolJ;
        var id = layui.router().search.id;
        var type = layui.router().search.type;
          //导出
        $("body").off('click.export1').on('click.export1', '.export1', function () {
            $(".layui-inline[lay-event='LAYTABLE_EXPORT']").click();
            $(".tab1 li[data-type='csv']").click();
        })
        function tableView(data) {
            var url = '';
            var jdata = '';
            if (data.length > 0) {
                jdata = data;
            } else {
                url = 'index/Distribution/detail';
            }
            table.render({
                elem: '#LAY-list'
                , url: url
                , data: jdata
                , toolbar: true
                , defaultToolbar: ['exports', 'filter', 'print']
                , cellMinWidth: 80
                , cols: [[
                     {field: 'sku', title: 'sku', edit: 'text'}
                    , {field: 'sku_name', title: '采购名称'}
                    , {field: 'quantity', title: '数量', edit: 'text'}
                    , {field: 'available_stock', title: '可用库存'}
                    , {field: 'price', title: '参考价（¥）'}
                    , {field: 'code', title: '配送计划单号'}
                ]]
                , page: true
                , limit: 10
                ,text:{none: '暂无相关数据!' }
            });
        }
        function viewHtml(data) {
            var getTpl = page1.innerHTML
                , view = $('#view');
            laytpl(getTpl).render(data, function (html) {
                view.html(html);
            });
            laydate.render({
                elem: '#fy1Time'
                , value: data.plan.distribution_time ? data.plan.distribution_time : ''
            });
           tableView(data.detail);

            table.render(null, 'LAY-list');
            form.render(null, 'LAY-list-form');
            //监听提交
            form.on('submit(LAY-submit-1)', function (data) {
                if (typeof table.cache['LAY-list'] != 'undefined' && table.cache['LAY-list'].length > 0) {
                    data.field.list = JSON.stringify(table.cache['LAY-list']);
                    console.log(JSON.stringify(data.field.list));
                    toolJ.ajax({"data": data.field});
                } else {
                    toolJ.error('不存在明细!');
                }
            });
        };
        $('body').off('click.auditSuccess').on('click.auditSuccess', '#auditSuccess', function () {
            toolJ.ajax({"data": {"id":id,"status":2}, "type": "post","url":"index/Distribution/audithandle"});
        });
        $('body').off('click.auditCancel').on('click.auditCancel', '#auditCancel', function () {
            toolJ.ajax({"data": {"id":id,"status":3}, "type": "post","url":"index/Distribution/audithandle"});
        });
        var info = {};
        toolJ.ajax({"data": {"id": id}, "type": "get"},
            function (data) {
                info.myCompany=data.data.myCompany;
                info.lsCompany=data.data.lsCompany;
                info.countryWarehouse=data.data.countryWarehouse;
                viewHtml({"info": info, "plan": data.data.plan, "type": 1, "detail": data.data.detail});
            }
        );

    })
</script>